<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
/*去掉所有空格*/
function trimall($str)//删除空格
{
    $qian=array(" ","　","\t","\n","\r");$hou=array("","","","","");
    return str_replace($qian,$hou,$str);    
}

/*获取网络数据*/
function get_net_data($url) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		return curl_exec($ch);
}

/**
 * 发送短信验证码
 * */
function send_msg_code($mobile){
	if(preg_match("/^1[345678]\d{9}$/", $mobile)){
		$code=rand(10000,99999);
		$url="http://www.ztsms.cn:8800/sendSms.do?username=xiaolijob&password=2rCXWG71&mobile=$mobile&content=您的短信验证码是".$code."！请妥善保管【重庆一厘米科技】&dstime=&productid=95533&xh=";
		$result=get_net_data($url);
		if(strpos('1,', $result)==0){
			return array("flag"=>true,"data"=>$code,"msg"=>"成功");
		}else{
			return array("flag"=>false,"data"=>$result,"msg"=>"发送失败");
		}
	}else{
			return array("flag"=>false,"data"=>"","msg"=>"手机号码格式错误");
	}
}